package spring.security.web.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/async")
public class AsyncController {

	@Autowired
	private MockQueue mockQueue;
	@Autowired
	private DeferredResultHolder deferredResultHolder; 
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@GetMapping
	public String order() throws Exception {
		logger.info("主线程开始");
		
		/*String orderNumber = RandomStringUtils.randomNumeric(8);
		
		mockQueue.setPlaceOrder(orderNumber);
		
		DeferredResult<String> result = new DeferredResult<String>();
		deferredResultHolder.getMap().put(orderNumber, result);
		
		logger.info("主线程返回");*/
		
		return "success";
	}
	
	/*Callable<String> callable = new Callable<String>() {

		@Override
		public String call() throws Exception {
			logger.info("副线程开始");
			Thread.sleep(2000);
			logger.info("副线程结束");
			return "1";
		}
	};*/
	
}
